package com.wulin.wucut.domain.entity.draft.meta.info;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.wulin.wucut.common.JianYinConstant;
import com.wulin.wucut.utils.JianYinUtil;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;


public class DraftMetaInfo {
    
    
    
    @JsonIgnore
    private   JSONObject originMetaInfo;  
    
    public DraftMetaInfo(){
        init();
    }
    
    @JsonProperty("draft_fold_path")
    private String draftFoldPath;

    @JsonProperty("draft_materials")
    private List<DraftMaterials> draftMaterials;


    public void appendMaterialType0(List<DraftMaterialsValue> values) {
        DraftMaterials materials = CollUtil.findOne(this.draftMaterials, t -> JianYinConstant.DRAFT_MATERIALS_TYPE.equals(t.getType()));
        List<DraftMaterialsValue> materialsValue = materials.getValue();
        materialsValue.addAll(values);
        materials.setValue(materialsValue);
        originMetaInfo.put(JianYinConstant.DRAFT_MATERIALS, draftMaterials);
        JianYinUtil.write(originMetaInfo.toString());
    }
    
    public void init() {
        originMetaInfo = JianYinUtil.getDraftMetaInfo();
        JSONArray jsonArray = originMetaInfo.getJSONArray(JianYinConstant.DRAFT_MATERIALS);
        this.draftMaterials = jsonArray.toJavaList(DraftMaterials.class);
    }
    

    public String getDraftFoldPath() {
        return draftFoldPath;
    }

    public void setDraftFoldPath(String draftFoldPath) {
        this.draftFoldPath = draftFoldPath;
    }

    public List<DraftMaterials> getDraftMaterials() {
        return draftMaterials;
    }

    public void setDraftMaterials(List<DraftMaterials> draftMaterials) {
        this.draftMaterials = draftMaterials;
    }
    
 
}
